package com.lhy.controller;

import com.lhy.pojo.Miner;
import com.lhy.pojo.User;
import com.lhy.service.MinerService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;


@RestController
@RequestMapping("miner")
public class MinerController {
    @Resource
    private MinerService minerService;

    //添加矿工信息到mongodb
    @PostMapping("add")
    public String addMiner(Miner miner){
        minerService.addMiner(miner);
        return "信息添加成功";
    }

    @GetMapping("{id}")
    public Miner selectMinerById(@PathVariable String id){
        return minerService.selectMinerById(id);
    }

    @GetMapping("{name}")
    public Miner selectMinerByName(@PathVariable String name){
        return minerService.selectMinerByName(name);
    }

    //查询所有
    @GetMapping("list")
    public Map<String,Object> selectMinerList(){
        return minerService.selectMinerList();
    }

    @GetMapping("listOn")
    public Map<String,Object> selectMinerListOn(){
        return minerService.selectMinerListOn();
    }

    //根据工号删除矿工信息
    @PostMapping("delete")
    public String deleteMinerById(String id){
        minerService.deleteMinerById(id);
        return "删除成功";
    }

    //根据工号修改矿工信息
    @PostMapping("update")
    public String updateMinerInfo(Miner miner){
        minerService.updateMinerInfo(miner);
        return "修改成功";
    }

}
